package training.队列栈;

import java.util.Stack;

public class ValidSmico {

    public static void main(String[] args) {

        System.out.println(isValid("[]"));
    }


    public static boolean isValid(String s) {


        Stack<Character> stack = new Stack<>();

        char c;
        int i = 0;
        while (i < s.length()) {

            c = s.charAt(i);

            switch (c) {

                case '(':stack.push(')');
                break;

                case '[':

                    stack.push(']');
                    break;

                case ')':

                case ']':
                    if (stack.isEmpty() || stack.pop() != c)
                        return false;
            }

            i++;
        }

        return stack.empty();
    }
}
